package com.baizhi.controller;

import com.baizhi.entity.Result;
import com.baizhi.pojo.Count;
import com.baizhi.pojo.Goods;
import com.baizhi.entity.PageResult;
import com.baizhi.entity.QueryPageBean;
import com.baizhi.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class GoodsController {
    @Autowired
    GoodsService goodsService;


    /**
     * 分页查询
     * @param queryPageBean
     * @return
     */
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        return goodsService.findPage(queryPageBean);
    }

    /**
     * 添加
     * @param goods
     * @return
     */
    @RequestMapping("/insertGoods")
    public void insertGoods(@RequestBody Goods goods){
        goodsService.insertGoods(goods);
    }

    /**
     * 根据id查询
     * @param id
     * @return
     */
    @RequestMapping("findById")
    public Goods findById(@RequestParam Long id){
       return goodsService.findById(id);
    }

    /**
     * 修改
     * @param goods
     * @return
     */
    @RequestMapping("/edit")
    public Integer edit(@RequestBody Goods goods){
       return goodsService.edit(goods);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("delete")
    public Integer delete(@RequestParam Long id){
       return goodsService.delete(id);
    }


    /**
     * 修改状态
     * @param id
     * @param status
     * @return
     */
    @RequestMapping("editStatus")
    public Integer editStatus(@RequestParam Long id,@RequestParam Integer status){
        return goodsService.editStatus(id,status);
    }


    /**
     * 状态因为
     * @param id
     * @param status
     * @param b
     * @return
     */
    @RequestMapping("/updateStatusAndBecause")
    public Integer updateStatusAndBecause(@RequestParam Integer id,@RequestParam Integer status,@RequestParam String b){
        return goodsService.updateStatusAndBecause(id,status,b);
    }


    /**
     * 统计图
     * @return
     */
    @RequestMapping("/count")
    public List<Count> count(){
        return goodsService.count();
    }
}
